package com.gouaixin.bee.beeframework2.activity;
//
//                       __
//                      /\ \   _
//    ____    ____   ___\ \ \_/ \           _____    ___     ___
//   / _  \  / __ \ / __ \ \    <     __   /\__  \  / __ \  / __ \
//  /\ \_\ \/\  __//\  __/\ \ \\ \   /\_\  \/_/  / /\ \_\ \/\ \_\ \
//  \ \____ \ \____\ \____\\ \_\\_\  \/_/   /\____\\ \____/\ \____/
//   \/____\ \/____/\/____/ \/_//_/         \/____/ \/___/  \/___/
//     /\____/
//     \/___/
//
//  Powered by BeeFramework
//

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.adapter.mPagerAdapter;

import java.util.ArrayList;




public class LeadActivity extends Activity {
    Context context=LeadActivity.this;


    ViewPager viewpager;
    mPagerAdapter adapter;
    private int currentPageIndex = 0;
    private ArrayList<View> datas;

    int oldTemp;//记录变化状态的最大值

    ImageView jinru;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery_image);

        initImageView();
        initViewPager();

    }

    /**
     * 图片视图的设置和监听
     */
    private void initImageView() {
        jinru = (ImageView) findViewById(R.id.jinru);
        jinru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                android.util.Log.e("Demo", "进入注册登录界面");

                Intent mainIntent = new Intent().setClass(LeadActivity.this, A1_SigninActivity.class);
                startActivity(mainIntent);
                finish();
//                overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
            }
        });

    }

    /***
     * ViewPager的设置和监听
     */
    private void initViewPager() {
        viewpager = (ViewPager) findViewById(R.id.image_pager);
        adapter = new mPagerAdapter();
        datas = new ArrayList<View>();
        datas.add(LayoutInflater.from(context).inflate(R.layout.banner1, null));
        datas.add(LayoutInflater.from(context).inflate(R.layout.banner2, null));
        datas.add(LayoutInflater.from(context).inflate(R.layout.banner3, null));

        adapter.setDatas(datas);
        adapter.notifyDataSetChanged();

        viewpager.setAdapter(adapter);
        viewpager.setCurrentItem(0);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                android.util.Log.e("Demo", "ViewPagerAdapter移动onPageScrolled：左边的页面：" +
                        arg0 + "\t偏移百分比：" + arg1 + "\t偏移像素值：" + arg2);


            }

            @Override
            public void onPageSelected(int i) {
                currentPageIndex = i;

            }

            @Override
            public void onPageScrollStateChanged(int i) {
//                android.util.Log.e("Demo", "ViewPager移动状态值（0无变化；1正在变化；2变化结束）：>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +
//                        i);

                if (i >= oldTemp) {
                    oldTemp = i;
                }

                if (i == 0) {
//                    android.util.Log.e("Demo", "当前oldTemp:"+oldTemp);
//                    android.util.Log.e("Demo", "当前currentPageIndex:"+currentPageIndex);

                    if (currentPageIndex == datas.size() - 1 && oldTemp == 1) {
                        android.util.Log.e("Demo", "跳转到页面0");
                        viewpager.setCurrentItem(0);
//                        Intent mainIntent = new Intent().setClass(LeadActivity.this, MyMainActivity.class);
//                        startActivity(mainIntent);
//                        finish();
//                        overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
                    }

                    if (currentPageIndex == 0 && oldTemp == 1) {
                        android.util.Log.e("Demo", "跳转到页面2");
                        viewpager.setCurrentItem(datas.size() - 1);

//                        Intent mainIntent = new Intent().setClass(LeadActivity.this, MyMainActivity.class);
//                        startActivity(mainIntent);
//                        finish();
//                        overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
                    }

                    oldTemp = 0;
//                    android.util.Log.e("Demo", "判断并清空后oldTemp:"+oldTemp);
                }


            }
        });


    }


}
